Xbasic

Array property_order Method

Syntax

dim Array_Order as C = <array>.property_order(field as c, values as c)

Arguments

fieldCharacter

The name of the property to use for reordering.

valuesCharacter

The values of the property to use for reordering.

Returns

Array_OrderCharacter

Returns a CR-LF delimited list of array indices listing the new position of each array element.

Description

Get a property array order list.

Discussion

The <array>.property_order() method creates a list containing the sequence of reordered array elements. Use the <array>.reorder() method to resequence the array.

Example

Create an array named arr and populate it with name and desc properties.

dim data as C
data  = <<%str% 
 One|first one 
 Two|second one 
 Three|third one 
 %str%
dim arr[3] as P
arr.initialize_properties("name|desc", data)
? arr
+[1].
+[2].
+[3].

Define an arbitrary order for the name property in the array.

dim refList as C
refList = comma_to_crlf("Two,One,Three") 

? reflist
= Two
One
Three

Create a string that defines how the array should be reordered.

ord = arr.property_order("name",refList) 

? ord
= 2
1
3

Now sort the array based on this new order.

arr.reorder(ord)

? arr.dump_properties("name|desc") 
=  Two|second one 
One|first one 
Three|third one

See Also